public class LengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        int maxLength = 0;
        char[] c = s.toCharArray();
        int[] hash = new int[128];
        for (int left = 0, right = 0; right < c.length; right++) {
            if (hash[c[right]]++ == 0) {
                maxLength = Math.max(maxLength, right-left+1);
            }
            while (left < right && hash[c[right]] > 1) {
                hash[c[left++]]--;
            }
        }
        return maxLength;
    }

    public static void main(String[] args) {
        System.out.println(new LengthOfLongestSubstring().lengthOfLongestSubstring("dvdf"));
    }
}
